package rpg.animation
{
	import rpg.Utils.Log;
	import rpg.Utils.Val;
	import rpg.data.ResData;
	import rpg.resource.PreLoad;
	import rpg.resource.Resource;
	import rpg.resource.Resources;
	import rpg.resource.SWFResource;

	public class AvatarAnimation extends Animation
	{
		/**
		 * 一个动作的描述,用来完成加载后初始化
		 */
		public var avatarActionDes : AvatarActionDescription;
		public var avatarActionID : String;

		public function AvatarAnimation(id : String)
		{
			super(id);
		}

		/**
		 * 加载动画
		 * @param resoureceId
		 *
		 */
		override public function loadAnimation() : void
		{
			if(!isNeedDownLoadAnimation)
				return;
			isNeedDownLoadAnimation = false;
			if(loadAnimationFrames[resoureceId])
				return;
			loadAnimationFrames[resoureceId] = true;
			Log.print("正在加载:" , PreLoad.resUrl + resoureceId);
			Resources.getInstance().preload(PreLoad.resUrl + resoureceId , ResData.SWF , Val.LOAD_LVEVEL_ROLE , animationComplete);
		}

		/**
		 * 完成动画加载,把图片加载到frame里面
		 * @param res
		 *
		 */
		override protected function animationComplete(res : Resource) : void
		{
			for each(var dir : String in avatarActionDes.dirs)
			{
				var tmpFrames : Array = saveAnimationFrames[avatarActionID + dir];
				for each(var frame : Frame in tmpFrames)
				{
					var resClass : Class = SWFResource(res).getAssetClass("Pic" + frame.name);
					frame.frameClass = resClass;
				}
			}
		}

		override public function destroy() : void
		{
			super.destroy();
			avatarActionDes = null;
		}
	}
}